#pragma once
#include <QHostAddress>
#include <QList>
#include "ManagerBase.h"
#include "MessageHelper.h"
#include "RoomManager.h"
#include "DBManager.h"
#include "../user/AbstractUser.h"
#include "HistoryHelper.h"
#include "User.h"

class UDPManager : public ManagerBase<UDPManager> {
public:
    void receiveData(const QByteArray& data, const QHostAddress& sender, quint16 senderPort);
    void receiveMsg(const MSG& msg, const QHostAddress& sender, quint16 senderPort);

    void sendToUser(AbstractUser* user, const QByteArray& data);

private:
    QByteArray makeCreatedMsg(quint16 roomId);
    QByteArray makeJoinedMsg(AbstractRoom* room, quint16 excludeUserId);
    QByteArray makeOtherJoinedMsg(quint16 userId);
    QByteArray makeOtherLeavedMsg(quint16 userId);
    QByteArray makeInviteMsg(const quint16& hostId);
    QByteArray makeDbStatusMsg(STATUS status, const quint16 userId = 0);
    QByteArray makeHistoryMsg(const QList<History>& historyList);
    QByteArray makeExpertsMsg(const QList<User>& expertList);
    QByteArray makeInvitationsMsg(const QList<Invitation>& invitations);

    void sendMessage(const QByteArray& data, const QHostAddress& addr, quint16 port);

    bool recvPing(const QByteArray& data);
};
